<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <canvas width="600" height="400" style="border: 2px solid black;"></canvas>
    <script>
        let canvas = document.querySelector('canvas');
        console.log(canvas);
        let ctx = canvas.getContext('2d');
        ctx.beginPath();
        ctx.moveTo(0,0);
        ctx.lineTo(600,400);
        ctx.stroke();//别忘了这一步
        ctx.closePath();
    </script>
</body>
</html>